#include<bits/stdc++.h>
using namespace std;
int n;
long long a[200005],dp[200005],dp2[200005],ans;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int ttt;
    scanf("%d",&ttt);
    for(int tttt=1;tttt<=ttt;tttt++){
        memset(dp,0,sizeof(dp));
        memset(dp2,0,sizeof(dp2));
        scanf("%d",&n);
            for(int i=1;i<=n;i++){
                scanf("%lld",&a[i]);
            }
            for(int i=1;i<=n;i++){
                for(int j=1;j<i;j++){
                    if(a[j-1]!=a[i]){
                        dp[i]=max(dp[i],dp[j]);
                    }
                    else{
                        dp[i]=max(dp[i],dp[j]+a[i]);
                    }
                }
                if(a[i]==a[i-1]){
                    for(int j=1;j<i;j++){
                        dp[j]+=a[i];
                    }
                }
            }
            ans=-1;
            for(int i=1;i<=n;i++){
                ans=max(ans,dp[i]);
            }
            printf("%lld\n",ans);
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
